using MediatR;
using WeatherMcpServer.Data.Entities;
using WeatherMcpServer.Data.Repositories;

namespace WeatherMcpServer.Application.Alerts.Queries;

/// <summary>
/// 查询预警列表（带简单过滤与分页）。
/// </summary>
public record GetAlertsQuery(
    WeatherType? Type,
    AlertStatus? Status,
    string? RegionCode,
    DateTime? FromUtc,
    DateTime? ToUtc,
    int Skip = 0,
    int Take = 50
) : IRequest<IReadOnlyList<WeatherAlert>>;

public class GetAlertsHandler : IRequestHandler<GetAlertsQuery, IReadOnlyList<WeatherAlert>>
{
    private readonly IWeatherAlertRepository _repo;

    public GetAlertsHandler(IWeatherAlertRepository repo)
    {
        _repo = repo;
    }

    public Task<IReadOnlyList<WeatherAlert>> Handle(GetAlertsQuery request, CancellationToken cancellationToken)
        => _repo.QueryAsync(request.Type, request.Status, request.RegionCode, request.FromUtc, request.ToUtc, request.Skip, request.Take, cancellationToken);
}
